package com.conncui.common.classoperate;

import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;

public class ClassExec {
    public static void save(Class<?> clazz, String outPut) {
        System.out.println("ClassSave:" + clazz.getClasses().toString());
        Object result = null;
        try {
            Method dumpMethod = clazz.getMethod("dump", new  Class[ 0 ]);
            result = dumpMethod.invoke(null, new Object[ 0 ]);

        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            byte[] data = (byte[]) (result);
            outPut(data, outPut);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void outPut(byte[] data, String outPut) throws Exception {
        //输出
//        File f = new File("/Users/cuiguoqiang/work/oschina/AndroidProject/ConnCommonAndroid/build/intermediates/classes/test/debug_2/com/conncui/generic/Generic.class");
        File f = new File(outPut);
        System.out.println(f.getAbsolutePath() + " exists : " + f.exists());
        FileOutputStream fout = new FileOutputStream(f);
        fout.write(data);
        fout.close();
        System.out.println("now generator cc success");
    }
}
